-
Notifications
You must be signed in to change notification settings - Fork 65
FXC-2053 Convenience functions for lumped port model setup #2928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 1 comment
d0f1fc3 to
78aa1b9
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/plugins/smatrix/ports/rectangular_lumped.pyLines 356-364 356 normal_axis, normal_coord = Geometry.parse_xyz_kwargs(x=x, y=y, z=z)
357
358 # make sure voltage axis was specified
359 if voltage_axis is None:
! 360 raise ValueError(
361 "No voltage axis was provided. Please make sure a valid voltage axis is specified."
362 )
363
364 # make sure normal is orthogonal to voltage axisLines 398-406 398 voltage_axis_2d = 1 - lateral_axis_2d
399
400 # Check: structures intersects plane
401 if len(grounds_2d) == 0:
! 402 raise ValueError("Ground structure does not intersect Lumped Port plane.")
403 if len(signals_2d) == 0:
404 raise ValueError("Signal structure does not intersect Lumped Port plane.")
405
406 # Get 2 element list with index 0 = ground shape and index 1 = signal shapeLines 413-421 413 # If lateral_coord is specified, pick ground/signal shape based on intersection
414 if lateral_coord is not None:
415 # constract a line along voltage axis in the lumped port plane going throung the lateral coordinate
416 if voltage_axis_2d == 0:
! 417 line = Geometry.make_shapely_box(-np.inf, lateral_coord, np.inf, lateral_coord)
418 else:
419 line = Geometry.make_shapely_box(lateral_coord, -np.inf, lateral_coord, np.inf)
420
421 # collect all geometries in shapes that intersect the lineLines 433-441 433 sel_shape = union_all(shapes)
434
435 # Check Lumped Port plane intersects a terminal
436 if sel_shape.is_empty:
! 437 raise ValidationError(
438 f"{name} terminal is not intersecting the lumped port plane or lateral coordinate."
439 "Please make sure the lumped port plane and/or terminals are specified correctly."
440 )
441 if isinstance(sel_shape, BaseMultipartGeometry):Lines 457-465 457 ground_2d, signal_2d = shape_list
458
459 # ensure that signal and ground terminals do not intersect
460 if ground_2d.intersects(signal_2d):
! 461 raise ValidationError(
462 "Ground intersects signal in the specified plane."
463 "Please make sure that ground and signal terminals do not overlap."
464 )Lines 474-482 474 return not (a_max < b_min or a_min > b_max)
475
476 # ensure that terminal bounding boxes don't overlap along voltage axis
477 if intervals_overlap(ground_bounds[voltage_axis_2d], signal_bounds[voltage_axis_2d]):
! 478 raise ValidationError(
479 "Auto-generation of lumped port failed because ground and signal terminals have overlapping bounds along voltage axis. "
480 "Please define lumped port manually."
481 )
482 # ensure that terminal bounding boxes overlap in lateral directionLines 480-488 480 "Please define lumped port manually."
481 )
482 # ensure that terminal bounding boxes overlap in lateral direction
483 if not intervals_overlap(ground_bounds[lateral_axis_2d], signal_bounds[lateral_axis_2d]):
! 484 raise ValidationError(
485 "Auto-generation of lumped port failed because ground and signal terminals "
486 "don't have overlapping bounds along lateral axis. "
487 "Please define lumped port manually."
488 )Lines 503-512 503 lateral_coord + port_width / 2,
504 )
505 else:
506 # If only port_width is specified, set based on bounds
! 507 lcenter = (lmin + lmax) / 2
! 508 lmin_new, lmax_new = (lcenter - port_width / 2, lcenter + port_width / 2)
509 # make sure that port_width does not exceed width of terminal overlap along lateral axis.
510
511 if lmin_new < lmin or lmax_new > lmax:
512 raise ValueError( |
7ebe90f to
f3703b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for those nice convenient features! Two main comments:
- When both lateral_coord and port_width are specified, it appears that ground and signal structures are not needed. Maybe we should move this to a separate method, e.g.
from_lateral_dimension. As forfrom_structures,port_widthoption is good to have, butlateral_coordis not needed; - The number of shapes from
intersections_planecan often be more than one, in particular if GeometryGroup or ClipOperation is used. Maybe we can merge shapes that intersect (e.g. shapely'sunion_all), and pick the nearest shapes between ground and signal to define the lumped port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, added a few comments/suggestions.
Also, it might make sense to name padding functions as padded_copy/uniformly_padded_copy (or copy_with_padding/copy_with_uniform_padding, or even add_padding_copy/add_uniform_padding_copy) to emphasize we are not modifying simulation object in place and be consistent with other functions like updated_copy, perutbed_mediums_copy, symmetry_expanded_copy, etc
27b592c to
b184600
Compare
I disagree: the specified
Good point! |
b184600 to
ed1277d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a couple more very minor comments from me
b85170e to
c3d824d
Compare
You are right. I missed this part! |
59f5786 to
4f75613
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to send the last comment
4f75613 to
80fe165
Compare
80fe165 to
9ab1f41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All look good to me!
9ab1f41 to
8d4670b
Compare
8d4670b to
63cb418
Compare
This PR introduces the first two automation utilities described in the corresponding Jira ticket aimed at simplifying model setup for lumped port simulations.
Added functions:
LumpedPort.from_structures()– Creates a lumped port by specifying a port plane (e.g. x = -L) together with the signal and ground structures. This helps automate port definition and reduce repetitive setup steps.Simulation.padded_copy()– Adds padding layers automatically along simulation boundaries. Follows a similar specification style to BoundarySpec, supporting both uniform and side-specific padding.Simulation.uniformly_padded_copy()- Applies padding uniformly along all simulation boundaries.Motivation:
These utilities streamline the setup process for common notebook workflows involving lumped ports and improve consistency across examples.